Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mysql

Package Overview
Dependencies
Maintainers
4
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql

A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.

  • 2.18.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
420K
decreased by-52.53%
Maintainers
4
Weekly downloads
 
Created

What is mysql?

The mysql npm package is a Node.js client for interacting with MySQL databases. It allows users to connect to a MySQL database, execute queries, and handle database operations asynchronously.

What are mysql's main functionalities?

Connecting to a MySQL database

This code establishes a connection to a MySQL database using the provided credentials.

const mysql = require('mysql');
const connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'me',
  password : 'secret',
  database : 'my_db'
});
connection.connect();

Executing a query

This code executes a SQL query to select all records from 'my_table' and logs the results.

connection.query('SELECT * FROM my_table', (error, results, fields) => {
  if (error) throw error;
  console.log(results);
});

Inserting data

This code inserts a new record into the 'posts' table with the provided data object.

const post  = {id: 1, title: 'Hello MySQL'};
const query = connection.query('INSERT INTO posts SET ?', post, (error, results, fields) => {
  if (error) throw error;
  // Neat!
});

Updating data

This code updates the title of a record in the 'posts' table where the id is 5.

connection.query('UPDATE posts SET title = ? WHERE id = ?', ['Hello World', 5], (error, results, fields) => {
  if (error) throw error;
  // Updated successfully
});

Closing the connection

This code closes the connection to the MySQL database.

connection.end();

Other packages similar to mysql

FAQs

Package last updated on 23 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc